package com.chy.dao.impl;

import com.chy.bean.User;
import com.chy.dao.LoginDao;
import com.chy.jdbcutil.JDBCUtil;
import org.springframework.stereotype.Repository;

import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@Repository
public class LoginDaoImpl extends JDBCUtil implements LoginDao {
    private boolean flag = true;
    @Override
    public Boolean login(User user) {
        try {
            JDBCUtil.testConnection();
            PreparedStatement pstm = conn.prepareStatement("select * from user where username = ? and password = ? ");
            pstm.setString(1, user.getUsername());
            pstm.setString(2, user.getPassword());
            ResultSet resultSet = pstm.executeQuery();
            if (resultSet.next()) {
                return flag;
            }else {
                flag = false;
                return flag;
            }
        } catch (ClassNotFoundException | IOException | SQLException e) {
            System.out.println("e = " + e);
        }
        return flag;
    }
}
